﻿package  
{
	import as3.collections.IMap;
	import as3.collections.LinkedMap;
	import commands.request.IRequestable;
	import commands.request.IRequestCommands;
	import commands.SearchProductCommand;
	import commands.request.impl.RequestCommandSet;
	/**
	 * ...
	 * @author Rami
	 */
	public class Proactor
	{
		private var connector:SocketConnector ;
		private var requestCommandsMap:IMap;
		
		public function Proactor(connector:SocketConnector) 
		{
			this.connector = connector;
			this.requestCommandsMap = new LinkedMap();
			this.registerRequests();
		}
		private function registerRequests():void
		{
			this.requestCommandsMap.addItem(SearchProductCommand.SEARCH_COMMAND, new SearchProductCommand());
		}
		
		public function getRequestCommandByName(requestName : String) : IRequestable
		{
			var request : IRequestable = this.requestCommandsMap.getItem(requestName) as IRequestable;
			return request;
		}
		
		public function createNewRequestCommandsSet():IRequestCommands
		{
			return new RequestCommandSet();
		}
		
		public function sendCommands(commandsSet:IRequestCommands):void
		{
			this.connector.sendCommand(commandsSet.retrieveFullCommands());
		}
		
	}

}